<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\CommentsSearch */

$this->title = '刷新评论redis';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comments-index">

    <?php
    \Yii::$container->set(\yii\widgets\ActiveField::className(), ['template' => "{label}\n{input}\n{hint}"]);
    $form = ActiveForm::begin([
/*        'action' => ['update-redis'],
        'method' => 'post',*/
        'options' => ['class' => 'form-inline'],
    ]); ?>

    <?= $form->field($model, 'comment_id_s')->textInput(['maxlength' => true]) ?>
    ~
    <?= $form->field($model, 'comment_id_e')->textInput(['maxlength' => true])->label(false) ?>
    <?= Html::button('刷新', ['id'=>'update', 'class' =>'btn btn-primary'])?>
<!--    <div class="form-group">
        <?/*= Html::submitButton('刷新', ['class' =>'btn btn-primary', 'id' => 'submit']) */?>
    </div>
-->
    <?php ActiveForm::end(); ?>
</div>
<?php $this->beginBlock('js'); ?>
<script>
    $(function(){

        $("#update").click(function(){
            var comment_id_s = $("[name='Comments[comment_id_s]']").val();
            var comment_id_e = $("[name='Comments[comment_id_e]']").val();
            if(isNaN(comment_id_s) || isNaN(comment_id_e)){
                alert('请输入数字');
                return false;
            }
            if(comment_id_e != '' && comment_id_e < comment_id_s){
                alert('起始ID不能大于结束ID');
                return false;
            }

            if(comment_id_s == '' ){
                alert('起始ID不能为空');
                return false;
            }
            else{
                $.ajax({
                    url: '<?=Yii::$app->urlManager->createUrl(Yii::$app->controller->id . '/update-redis')?>',
                    type: 'post',
                    data: {comment_id_s:comment_id_s, comment_id_e:comment_id_e},
                    dataType: 'json',
                    success: function(e){
                        alert(e.msg);
                    }
                });
            }

        });



    });


</script>
<?php $this->endBlock(); ?>